package com.javastudy.autowiredStudy.enableStudy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 目的是让所有的web应用实现日志打印
 * --
 * 第一步，定义logfilter
 * @author mac
 * @date 2021/9/7 4:58 下午
 */
@Slf4j
public class LogFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest servletRequest = (HttpServletRequest) request;
        String requestURI = servletRequest.getRequestURI();
        String method = servletRequest.getMethod();
        //处理请求之前
        log.info("业务接口 %S，请求参数：%S",requestURI,servletRequest.getParameterMap().toString());

        chain.doFilter(servletRequest,response);

        //处理请求时候
        log.info("请求结束了:%S","那我走");
    }
}
